#include "Scene.h"
#include "CharacterController.h"
#include "PCCharacterController.h"

class Character:public Scene
{
public:
	PCCharacterController* mChara;

	Character(SceneEvnArgs evn):Scene(evn){}

	bool frameRenderingQueued(const FrameEvent& evt)
	{
		// let character update animations and camera
		mChara->addTime(evt.timeSinceLastFrame);
		return Scene::frameRenderingQueued(evt);
	}
	
	bool keyPressed(const OIS::KeyEvent& evt)
	{
		// relay input events to character controller
		mChara->injectKeyDown(evt);
		return Scene::keyPressed(evt);
	}
	
	bool keyReleased(const OIS::KeyEvent& evt)
	{
		// relay input events to character controller
		mChara->injectKeyUp(evt);
		return Scene::keyReleased(evt);
	}

	bool mouseMoved(const OIS::MouseEvent& evt)
	{
		// relay input events to character controller
		mChara->injectMouseMove(evt);
		return Scene::mouseMoved(evt);
	}

	bool mousePressed(const OIS::MouseEvent& evt, OIS::MouseButtonID id)
	{
		// relay input events to character controller
		mChara->injectMouseDown(evt, id);
		return Scene::mousePressed(evt, id);
	}

	virtual void createScene(void) 
	{
		// set background and some fog
		mViewport->setBackgroundColour(ColourValue(1.0f, 1.0f, 0.8f));

		// set shadow properties
		mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
		mSceneMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5));
		mSceneMgr->setShadowTextureSize(1024);
		mSceneMgr->setShadowTextureCount(1);

		// disable default camera control so the character can do its own
		mCameraMan->setStyle(OgreBites::CS_MANUAL);

		// use a small amount of ambient lighting
		mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));

		// add a bright light above the scene
		Light* light = mSceneMgr->createLight();
		light->setType(Light::LT_POINT);
		light->setPosition(-10, 40, 20);
		light->setSpecularColour(ColourValue::White);

		// create a floor mesh resource
		MeshManager::getSingleton().createPlane("floor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			Plane(Ogre::Vector3::UNIT_Y, 0),200000, 200000, 20, 20, true, 1, 9000, 9000, Ogre::Vector3::UNIT_Z);

		// create a floor entity, give it a material, and place it at the origin
        Entity* floor = mSceneMgr->createEntity("Floor", "floor");
        floor->setMaterialName("Examples/BeachStones");
		floor->setCastShadows(false);
        mSceneMgr->getRootSceneNode()->attachObject(floor);

		if( !Kinect::getSingleton().isDown ) {
			PRINT("Hi, Kinect!");
			mChara = new CharacterController(mCamera);
		} else {
			mChara = new PCCharacterController(mCamera);
		}
	}

};